<template>
	<view>
		<view class="container">
			<view class="card my-3 p-4 type-box">
				<view class="title mb-4">
					物品类型<text class="red">(必填)</text>
				</view>
				<view class="list">
					<view v-for="(item, index) in list" :key="index" class="item" :class="{ active: active === index }" @tap="setPackage(index)">{{ item }}</view>
				</view>
				<view class="current">
					<input v-model="packageInfo.itemName" type="text" placeholder="可输入物品类型">
				</view>
				<view class="red">
					注意：请勿寄递国家机关公文件
				</view>
			</view>
			<view class="card my-3 p-4 measure-box">
				<view class="ss-flex ss-row-between mb-4">
					<view class="title">
						预估重量(kg)<text class="red">(必填)</text>
					</view>
					<uni-number-box v-model="packageInfo.weight" @change="onChange" />
				</view>
				<view class="red mb-5">
					注意：默认重量为1KG，可更改，实际重量以收件员确认为准，超出重量快件，需要补差价
				</view>
				<view class="title mb-4">
					货物尺寸(cm)<text class="red">(非必填)</text>
				</view>
				<view class="ss-flex size">
					<view class="label">
						长
					</view>
					<input type="number" v-model="packageInfo.vloumLong">
					<view class="label">
						宽
					</view>
					<input type="number" v-model="packageInfo.vloumWidth">
					<view class="label">
						高
					</view>
					<input type="number" v-model="packageInfo.vloumHeight">
				</view>
			</view>
			<view class="card my-3 p-4 tip-box">
				重要提示：<br/>17:30快递员就已经下班了，第二天才会取
			</view>
			<view class="card my-3 p-4">
				<view class="title mb-4">
					备注
				</view>
				<textarea class="textarea" placeholder="给快递小哥捎句话（不超过20字）" v-model="packageInfo.billRemark"></textarea>
			</view>
		</view>
		<view class="fixed">
			<button class="button" @tap="onConfirm">
				确定
			</button>
		</view>
	</view>
</template>

<script>
	var app = getApp();
	export default {
		data() {
			return {
				list:['文件','数码电器','衣服首饰','化妆品','食品','日用品','其他'],
				packageInfo:{
					itemName:'',
					weight:'',
					vloumLong:'',
					vloumWidth:'',
					vloumHeight:'',
					billRemark:''
				},
				active:''
			};
		},
		onLoad: function() {
			
		},
		onShow(){
			let that = this;
			that.packageInfo = uni.getStorageSync('kuaidi-date');
			that.active = '';
			that.list.forEach((res,index)=>{
				//console.log(index);
				if(res==that.packageInfo.itemName){
					that.active = index;
				}
			})
		},
		methods: {
			setPackage(num){
				let that = this;
				that.active = num;
				that.packageInfo.itemName = that.list[that.active]
			},
			onChange(e){
				//console.log(e);
			},
			onConfirm(){
				let that = this;
				var pages = getCurrentPages(); //当前页
				var beforePage = pages[pages.length - 2]; //上个页面
				uni.setStorageSync('kuaidi-date',that.packageInfo);
				// #ifdef H5
				beforePage.setAddress(2)
				// #endif
				// #ifndef H5
				beforePage.$vm.setAddress(2)
				// #endif
				app.goback(true);
			}
		}
	};
</script>

<style lang="scss" scoped>
	.container {
		width: 95%;
		margin: 0 auto;
		padding-bottom: 148rpx;
	}
	.card {
	    border-radius: 20rpx;
	    background-color: #fff;
	}
	.p-4 {
	    padding: 30rpx !important;
	}
	.my-3 {
	    margin-top: 20rpx !important;
	    margin-bottom: 20rpx !important;
	}
	.mb-4 {
	    margin-bottom: 30rpx !important;
	}
	.title {
		font-size: 32rpx;
		font-weight: 600;
		color: #000000;
	}
	.red {
		font-size: 24rpx;
		color: red;
	}
	.type-box {
		.list {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			row-gap: 40rpx;
			.item {
				width: calc((100% - 30px) / 3);
				height: 64rpx;
				line-height: 64rpx;
				text-align: center;
				color: #101010;
				border: 2rpx solid #eeeeee;
				border-radius: 64rpx;
				&.active {
					background-color: #0396ff;
					color: #fff;
				}
			}
		}
		.current {
			display: flex;
			align-items: center;
			height: 64rpx;
			border-radius: 64rpx;
			padding: 0 20rpx;
			border: 2rpx solid #eeeeee;
			color: #000000;
			font-size: 32rpx;
			margin: 40rpx 0;
		}
	}
	.measure-box {
		.size {
			height: 60rpx;
			line-height: 60rpx;
			text-align: center;
			color: #000000;
			border: 2rpx solid #eeeeee;
			.label {
				width: 110rpx;
				background-color: #eeeeee;
			}
			input {
				flex: 1;
			}
		}
	}
	.tip-box {
		font-size: 24rpx;
		color: #989898;
		line-height: 40rpx;
	}
	.textarea {
		width: auto;
		border: 2rpx solid #eeeeee;
		border-radius: 10rpx;
		color: #000000;
		height: 200rpx;
		padding: 10rpx;
	}
	.fixed {
		position: fixed;
		width: 100%;
		bottom: 0;
		padding: 30rpx;
		background-color: #fff;
		box-sizing: border-box;
		z-index: 99;
		.button {
			height: 88rpx;
			line-height: 88rpx;
			font-size: 36rpx;
			color: #fff;
			border-radius: 88rpx;
			background-color: #0396ff;
			outline: none;
			border: none;
		}
	}
	.ss-row-between {
	    justify-content: space-between;
	}
	.ss-flex {
	    display: flex;
	    flex-direction: row;
	    align-items: center;
	}
</style>